<?php

    require_once (dirname(__FILE__).'/config_fj.php');
	class Browser{
		public  $id;
		public  $name;//浏览者姓名
		public  $permission;
		public  $published_paper_order;
		public  $audit_permission;
		//$var_name="Anonymous",$var_permission="visitor",$var_id=""
		public function __construct($sql_info){
			
			$this->name=trim($sql_info['name']);
			$this->permission=trim($sql_info['role']);
			if($this->permission!='visitor'){
				$this->id=trim($sql_info['ID']);
				$this->published_paper_order=trim($sql_info['publication']);
			}
		}

		public function OtherInfo()
		{
			$this->setAudiPer(false);//初始化审核权限
			/*Maybe will not used*/
			//echo "Building personal information".EOL;
		}
		public function setAudiPer($val)
		{
			
			$this->audit_permission=$val;
			
		}
		

	}
	
	$link=LinkMysql();
	
	function getUserInfoFromSql($id)
	{
	    global $link;
	    $sql="SELECT * FROM ".TBLABP." WHERE ID = '$id' LIMIT 1";
	    $ret=MysqlQuery($link,DBLAB,$sql);
	    if(!$ret){
	        //for debug
	        echo "Sql:".$sql.EOL;
	        echo "query failed at file: ".__FILE__." LINE :".__LINE__." ".$link->error.EOL;
			exit;
	    }
	    else if($ret->num_rows){
	        return $ret->fetch_assoc();
	    }
	    else{//没有获取到给定ID的信息,生成访客信息
	        return array('ID'=>"",'role'=>"visitor","name"=>"Anonymous");
	    }
	}

	@session_start();
	//用户名 
	$user_id=empty($_SESSION['user'])?"Anonymous":$_SESSION['user'];
	
	//如果是同一人的话不需要重复查询数据库
	/*

		最好还是不要做成缓存，不然不能同步更新某些信息，但是非数据库信息可以做成缓存
		if(empty($_SESSION['user_fullinfo']) || $_SESSION['user_fullinfo']['ID']!=$user_id){
       $_SESSION['user_fullinfo']=getUserInfoFromSql($user_id);
	}
	*/
	$browser_info=new Browser(getUserInfoFromSql($user_id));
	$browser_info->OtherInfo();//获取浏览者的其他信息
?>